package toDo.pack;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class ToDoActivity extends Activity {
	public static User[] user;
	Button login;
	Button register;
	
	EditText username, password;
	TextView error;
	

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        user = new User[10];
        user[0]= new User("David","dlong","password","dlong88@gatech.edu");
        login = (Button) findViewById(R.id.blogin);
        register = (Button) findViewById(R.id.regswitch);
        username = (EditText) findViewById(R.id.tUsername);        
        password = (EditText) findViewById(R.id.tPassword);   
        error = (TextView) findViewById(R.id.tError);
        login.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				user = Register.getArray();
				String usertemp = username.getText().toString();
				String passtemp = password.getText().toString();
				boolean ver = verify(usertemp,passtemp);
				
				if(ver == false)
					error.setText("Invalid Username or Password");
				if(ver == true)
					error.setText("Login Correct");
			}
		});
        register.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent myIntent = new Intent(v.getContext(), Register.class);
				v.getContext().startActivity(myIntent);
			}
		});
    }
    public boolean verify(String username, String password){
    	for(int i = 0; i < user.length;i++){
    		if(user[i] != null){
    		if(user[i].getUsername() .equals(username)){
    			if(user[i].getPassword() .equals(password)){
    				//error.setText("Login Correct");
    				return true;
    			}
    		}
    	}
    	}
    	//error.setText("Invalid Username or Password");
    	return false;
    }
    public static User[] getArray(){
    	return user;
    }
}